package com.azkj.album.adapter;

import android.graphics.Color;

import com.azkj.album.R;
import com.azkj.album.dto.CategoryBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

public class CategoryAdapter extends BaseQuickAdapter<CategoryBean, BaseViewHolder> {

    private int curPosition = 0;

    public CategoryAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, CategoryBean item) {
        helper.setText(R.id.category_name, item.getName());
        if (curPosition == getItemPosition(item)) {
            helper.setTextColor(R.id.category_name, Color.parseColor("#478EF7"));
            helper.setBackgroundRes(R.id.category_name, R.drawable.shape_ebf3ff_corner_30);
        } else {
            helper.setTextColor(R.id.category_name, Color.parseColor("#484848"));
            helper.setBackgroundRes(R.id.category_name, R.drawable.shape_f4_corner_30);
        }
    }

    public void setCurPosition(int curPosition) {
        this.curPosition = curPosition;
        this.notifyDataSetChanged();
    }

    private int getItemPosition(CategoryBean item) {
        return item != null && mData != null && !mData.isEmpty() ? mData.indexOf(item) : -1;
    }
}
